{% extends 'base.html' %}

{% block title %}
  汇率管理 - 数据管理系统
{% endblock %}

{% block breadcrumb %}
  <li class="breadcrumb-item"><a href="{{ url_for('list_currencies') }}">货币管理</a></li>
  <li class="breadcrumb-item active" aria-current="page">汇率管理</li>
{% endblock %}

{% block content %}
  <div class="d-flex justify-content-between align-items-center mb-4">
    <h2 class="page-header">汇率列表</h2>
    {% if is_admin %}
      <a href="{{ url_for('add_exchange_rate') }}" class="btn btn-primary">
        <i class="bi bi-plus-lg"></i> 添加汇率
      </a>
    {% endif %}
  </div>

  <div class="table-responsive">
    <table class="table table-striped table-hover">
      <thead class="table-light">
        <tr>
          <th>日期</th>
          <th>货币</th>
          <th>基准货币</th>
          <th>汇率</th>
          <th>变化金额</th>
          <th>变化百分比</th>
          <th>来源</th>
          {% if is_admin %}
            <th>操作</th>
          {% endif %}
        </tr>
      </thead>
      <tbody>
        {% for rate in rates %}
          <tr>
            <td>{{ rate.collected_date.strftime('%Y-%m-%d') }}</td>
            <td>{{ rate.currency.code }} ({{ rate.currency.symbol }})</td>
            <td>{{ rate.base_currency_code }}</td>
            <td>{{ rate.rate }}</td>
            <td>{{ rate.change_amount if rate.change_amount is not none else '-' }}</td>
            <td>
              {% if rate.change_percent is not none %}
                {{ rate.change_percent }}%
                {% if rate.change_percent > 0 %}
                  <i class="bi bi-arrow-up text-success"></i>
                {% elif rate.change_percent < 0 %}
                  <i class="bi bi-arrow-down text-danger"></i>
                {% endif %}
              {% else %}
                -
              {% endif %}
            </td>
            <td>{{ rate.source or '-' }}</td>
            {% if is_admin %}
              <td class="action-buttons">
                <div class="d-flex gap-2">
                  <a href="{{ url_for('edit_exchange_rate', id=rate.id) }}" class="btn btn-sm btn-outline-primary">
                    <i class="bi bi-pencil"></i> 编辑
                  </a>
                  <button type="button" class="btn btn-sm btn-outline-danger" 
                    onclick="if(confirm('确定删除这条汇率记录吗?')) window.location='{{ url_for('delete_exchange_rate', id=rate.id) }}'">
                    <i class="bi bi-trash"></i> 删除
                  </button>
                </div>
              </td>
            {% endif %}
          </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
{% endblock %}